﻿<?php
include 'test_header.php';

class test_user_judge_statistics_process extends UnitTestCase{
	
	private $db ; 
	function setUp(){
		$this->db = db_connect();

		$sql = "
CREATE TABLE IF NOT EXISTS `user_judge_statistics` (
  `username` varchar(255) NOT NULL,
  `submit_times` bigint(20) NOT NULL,
  `accepted_times` bigint(20) NOT NULL,
  `wrong_answer_times` bigint(20) NOT NULL,
  `presentation_times` bigint(20) NOT NULL,
  `compilation_error_times` bigint(20) NOT NULL,
  `time_exceeded_times` bigint(20) NOT NULL,
  `memory_exceeded_times` bigint(20) NOT NULL,
  `output_exceeded_times` bigint(20) NOT NULL,
  `runtime_error_times` bigint(20) NOT NULL,
  `compile_time_over` bigint(20) NOT NULL,
  PRIMARY KEY (`username`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
	$res = $this->db->query( $sql );

	$sql = "
INSERT INTO  `user_judge_statistics` (
`username` ,
`submit_times` ,
`accepted_times` ,
`wrong_answer_times` ,
`presentation_times` ,
`compilation_error_times` ,
`time_exceeded_times` ,
`memory_exceeded_times` ,
`output_exceeded_times` ,
`runtime_error_times` ,
`compile_time_over`
)
VALUES (
'test',  '1000',  '1',  '2',  '3',  '4',  '5',  '6',  '7',  '8',  '9'
)";

$res = $this->db->query( $sql );

	}

	function tearDown(){
		
		$sql = "drop table user_judge_statistics";

		$res = $this->db->query( $sql );
	
	}

	function test_load_user_judge_statistics_process(){

		$username = 'test';
		$user_judge_stat_proc = new user_judge_statistics_process( $this->db );
		$this->assertTrue( $user_judge_stat_proc->load( 'username' , $username ) );
	}
	function test_plus_submit_times(){

		$username = 'test';
		$user_judge_stat_proc = new user_judge_statistics_process( $this->db );
		$this->assertTrue( $user_judge_stat_proc->load( 'username' , $username ) );
		$old_submit_times = $user_judge_stat_proc->get( 'submit_times' );
		$this->assertTrue( $user_judge_stat_proc->plus( 'submit_times' ) );
		$new_submit_times = $user_judge_stat_proc->get( 'submit_times' );
		$this->assertEqual( $new_submit_times , $old_submit_times + 1 );
	}
}
	

$test = new test_user_judge_statistics_process();
$test->run( new HtmlReporter() );
